<?php
    header("content-type:text/html;charset=utf-8");
    // $name = $_GET['username'];
    // $psw = $_GET['password'];
    $link = mysql_connect('localhost', 'root', 'root') or die('数据链接失败');
    mysql_select_db('xiaomi', $link);
    $keyword = $_POST['keyword'];
    $id = $_POST['id'];
    $sql = "select * from `home`";
    if($id) $sql .= "where id=$id";
    if($keyword) $sql .= "where `goods_name` LIKE '%$keyword%'";
    $res = mysql_query($sql);
     // 匹配就是$row就是一个resource
     // 匹配不上$row返回就是false boolean
    $arr = [];
    if($res){
        while($row = mysql_fetch_assoc($res)){
            array_push($arr,$row);
        }
    }
    echo json_encode($arr);
?>